package com.qfedu.dao;

import com.qfedu.entity.Depart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DepartmentDao {

    /**
     * 添加部门
     *
     * @param depart
     * @return
     */
    @Insert("insert into t_depart (name, createtime) values (#{name}, #{createtime})")
    public int addDepartment(Depart depart);

    /**
     * 查询所有部门
     *
     * @return
     */
    @Select("SELECT  d.id,d.createtime,d.name,d.flag,c.num FROM t_depart d LEFT JOIN (select  a.id,a.name, b.num FROM t_depart a, (select  COUNT(1) num,d_id FROM t_staff GROUP BY d_id) b where a.id = b.d_id) c on c.name = d.name")
    public List<Depart> findAllDepart();


    /**
     * 通过id删除部门
     *
     * @param id
     * @return
     */
    @Delete("delete from t_depart where id = #{id}")
    public int deleteDepartById(int id);

    /**
     * 更改部门信息
     *
     * @param depart
     * @return
     */
    @Update("update t_depart set name = #{name},createtime = #{createtime} where id = #{id}")
    public int updateDepartment(Depart depart);
}
